
package com.xyzq.hs.util;

public class StringUtils {

	/**
	 * convert opBranchNo to op_branch_no
	 * 
	 * @param propertyName
	 * @return
	 */
	public static String propertyNameToFieldName(String propertyName) {
		if (isBlank(propertyName))
			throw new IllegalArgumentException("propertyName must not be empty");
		char[] chars = propertyName.toCharArray();
		StringBuffer fieldName = new StringBuffer();
		for (char c : chars) {
			if (c >= 'A' && c <= 'Z')
				fieldName.append("_" + String.valueOf(c).toLowerCase());
			else
				fieldName.append(c);
		}
		return fieldName.toString();
	}

	/**
	 * 
	 * convert op_branch_no to opBranchNo
	 * 
	 * @param fieldName
	 * @return
	 */
	public static String fieldNameToPropertyName(String fieldName) {
		if (isBlank(fieldName))
			throw new IllegalArgumentException("fieldName must not be empty");
		char[] chars = fieldName.toCharArray();
		StringBuffer propertyName = new StringBuffer();
		for (int i = 0; i < chars.length; i++) {
			if (chars[i] == '_')
				propertyName.append(String.valueOf(chars[++i]).toUpperCase());
			else
				propertyName.append(chars[i]);
		}
		return propertyName.toString();
	}

	public static boolean isBlank(String str) {
		int strLen;
		if (str == null || (strLen = str.length()) == 0) {
			return true;
		}
		for (int i = 0; i < strLen; i++) {
			if ((Character.isWhitespace(str.charAt(i)) == false)) {
				return false;
			}
		}
		return true;
	}
	
	public static boolean isNotBlank(String str) {
		return !isBlank(str);
	}

}
